package com.apes.fn.fico.prepaid.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @Title: ShareDetail
 * @Description: 分摊明细表 (待摊费用分摊后写入此表)
 * @author: ZhengZeXian
 * @create: 2022/2/10 16:55
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ShareDetail.CONST_TABLE_NAME)
public class ShareDetail extends BaseModel {

    public static final String CONST_TABLE_NAME = "fn_share_detail";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "分摊明细表", padding = 7)
    @Comment("分摊明细编码")
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "prepaid_expense_item_id", referencedColumnName = "id")
    @Comment("待摊费用明细")
    private PrepaidExpenseItem prepaidExpenseItem;

    @Column(name = "share_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("分摊金额")
    private double shareAmount = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "share_person_id", referencedColumnName = "id")
    @Comment("分摊人")
    private PartyRole sharePerson;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Column(name = "share_date")
    @Comment("分摊日期")
    private Date shareDate;

    @States(name = "单据状态", values = {
            @State(id = "done", name = "完成"),
    })
    @Column(name = "state", length = 10, nullable = false)
    private String state;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Column(name = "post_date")
    @Comment("记账日期")
    private Date postDate;

    @Comment("公司")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    private PartyRole company;
}
